package com.javaee.lpr.config;

import com.javaee.lpr.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class LoginInterceptorConfigurer implements WebMvcConfigurer {
    @Override // 配置自定义拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        // 创建自定义拦截器对象
        HandlerInterceptor interceptor = new LoginInterceptor();
        // 配置白名单 List
        List<String> patterns = new ArrayList<>();
        // 添加资源白名单。。。
        patterns.add("/css/**");
        patterns.add("/web/login.html");
        // 添加路径白名单
        patterns.add("/user/log");
        patterns.add("/user/reg");
        // 注册
        registry.addInterceptor(interceptor)
                .addPathPatterns("/**") // 所有路径都拦截
                .excludePathPatterns(patterns); // 白名单List
    }
}
